<?php

namespace App\Http\Requests\Api\v2;

use App\Http\Requests\CommonRequest;
use App\Models\Api\v2\LiveOrders;

class LiveOrdersRequest extends CommonRequest
{
    public $scenes = [
        'pay' => 'order_no,order_id',
        'status' => 'id,status',
        'delivery' => 'id,is_delivery',
    ];

    public function rules()
    {
        $data = request()->all();

        return [
            'goods_id' => ['required'],
            'sum' => ['required'],
            'type' => ['required'],
            'remark' => ['required'],
            'order_no' => ['required'],
            'order_id' => ['required', function ($a, $v, $f) {
                if (!$info = LiveOrders::query()->find($v)) {
                    return $f('订单不存在！');
                }
                if ($info->status != 1) {
                    $message = $info->status == 2 ? "订单已支付" : "订单已过期";
                    return $f($message);
                }
//                if ($info->order_no != request()->json('order_no')) {
//                    return $f("Bad Request !");
//                };
            }],
        ];
    }


    public function statusRules()
    {
        return [
            'id' => ['required'],
            'status'=> ['required'],
        ];
    }

    public function deliveryRules()
    {
        return [
            'id' => ['required'],
            'is_delivery'=> ['required'],
        ];
    }


    public function messages()
    {
        return [
            'is_delivery.required' => "配送状态",
            'order_no.required' => "订单号不能为空",
            'order_id.required' => "订单ID不能为空",
            'id.required' => "订单ID不能为空",
            'status.required' => "订单状态不能为空",
        ];
    }
}
